<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<jsp:include page="../../header.jsp" />
<div class="content-header">
    <h2 class="content-title">${employee == null ? '添加新员工' : '编辑员工信息'}</h2>
    <div class="action-buttons">
        <a href="employee" class="btn btn-back">
            <i class="icon-back"></i> 返回列表
        </a>
    </div>
</div>

<div class="card">
    <div class="card-body">
        <form action="employee" method="post" class="employee-form">
            <input type="hidden" name="action" value="${employee == null ? 'insert' : 'update'}">
            <c:if test="${employee != null}">
                <input type="hidden" name="id" value="${employee.id}">
            </c:if>

            <div class="form-row">
                <div class="form-group">
                    <label for="name">姓名 <span class="required">*</span></label>
                    <input type="text" id="name" name="name" value="${employee.name}" required>
                </div>

                <div class="form-group">
                    <label>性别 <span class="required">*</span></label>
                    <div class="radio-group">
                        <label class="radio-label">
                            <input type="radio" name="gender" value="男"
                            ${employee.gender == '男' ? 'checked' : ''} required>
                            <span class="radio-custom"></span>
                            男
                        </label>
                        <label class="radio-label">
                            <input type="radio" name="gender" value="女"
                            ${employee.gender == '女' ? 'checked' : ''}>
                            <span class="radio-custom"></span>
                            女
                        </label>
                    </div>
                </div>
            </div>

            <div class="form-row">
                <div class="form-group">
                    <label for="birthDate">出生日期 <span class="required">*</span></label>
                    <input type="date" id="birthDate" name="birthDate"
                           value="${employee.birthDate}" required>
                </div>

                <div class="form-group">
                    <label for="hireDate">入职日期 <span class="required">*</span></label>
                    <input type="date" id="hireDate" name="hireDate"
                           value="${employee.hireDate}" required>
                </div>
            </div>

            <div class="form-row">
                <div class="form-group">
                    <label for="phone">电话 <span class="required">*</span></label>
                    <input type="tel" id="phone" name="phone" value="${employee.phone}" required>
                </div>

                <div class="form-group">
                    <label for="email">邮箱 <span class="required">*</span></label>
                    <input type="email" id="email" name="email" value="${employee.email}" required>
                </div>
            </div>

            <div class="form-row">
                <div class="form-group">
                    <label for="position">职位 <span class="required">*</span></label>
                    <input type="text" id="position" name="position" value="${employee.position}" required>
                </div>

                <div class="form-group">
                    <label for="departmentId">所属部门 <span class="required">*</span></label>
                    <select id="departmentId" name="departmentId" required>
                        <option value="">--请选择部门--</option>
                        <c:forEach items="${departments}" var="dept">
                            <option value="${dept.id}"
                                ${employee.departmentId == dept.id ? 'selected' : ''}>
                                    ${dept.name}
                            </option>
                        </c:forEach>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label for="address">联系地址</label>
                <textarea id="address" name="address" rows="2">${employee.address}</textarea>
            </div>

            <div class="form-actions">
                <button type="submit" class="btn btn-primary">
                    <i class="icon-save"></i> 保存信息
                </button>
                <button type="reset" class="btn btn-secondary">重置</button>
            </div>
        </form>
    </div>
</div>

<script>
    // 设置日期输入框的最大值
    const today = new Date().toISOString().split('T')[0];
    document.getElementById('birthDate').setAttribute('max', today);
    document.getElementById('hireDate').setAttribute('max', today);
</script>
<jsp:include page="../../footer.jsp" />